package org.hengguan.api.contest.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@ApiModel(value = "ResponseVo对象", description = "全局接口返回对象")
public class ResponseVo<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "返回状态码", example = "200")
	private Integer code = 200;
	@ApiModelProperty(value = "返回消息", example = "ok")
	private String message = "ok";
	@ApiModelProperty(value = "是否成功", example = "true")
	private Boolean success = Boolean.TRUE;
	@ApiModelProperty(value = "返回数据对象")
	private T data;
	@ApiModelProperty(value = "响应时间戳")
	private long timestamp = System.currentTimeMillis();

	private ResponseVo(String msg) {
		this.success = Boolean.FALSE;
		this.message = msg;
	}

	private ResponseVo(T t) {
		this.data = t;
	}

	public static <T> ResponseVo<T> ok(T t) {
		return new ResponseVo<T>(t);
	}
	public static <T> ResponseVo<T> ok() {
		return ResponseVo.ok(null);
	}
	public static <T> ResponseVo<T> error(String msg) {
		return new ResponseVo<T>(msg);
	}

}
